const fs = require("fs");

let cached = {};
function MyRequire(path) {

  if (cached[path]) {
    console.log("读取缓存: ", path);
    return cached[path].exports;
  }
  const module = {
    path,
    exports: {},
  };
  cached[path] = module;
  const content = fs.readFileSync(path, 'utf-8');
  eval(content)(module, module.exports, MyRequire);
  return module.exports;
}

const a = MyRequire("./a.js");
const b = MyRequire("./b.js");
console.log(a);
console.log(b);
